home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / music / gmsrc211.arj / ENV.ASM < prev    next >
Assembly Source File  |  1994-03-08  |  4KB  |  95 lines

  1. ; DS:SI  -- String to search for
  2. ; ES:DI  -- Place to put
  3. ; CX     -- Maximum size to copy
  4. ; AX     -- PspAddress
  5.  
  6. proc            sl_EnvString near
  7.                 cld                             ;work upward
  8.                 push    es di cx
  9.                 mov     es, ax
  10.                 mov     es,[es:2Ch]             ;ES:DI points at environment
  11.                 xor     di,di                   ;which is paragraph-aligned
  12.                 lodsb                           ;look at length
  13.                 or      al,al                   ;is it zero?
  14.                 je      @@RetNul                ;if so, return
  15.                 mov     ah,al                   ;otherwise, save in AH
  16.                 mov     dx,si                   ;DS:DX contains pointer to first parm char
  17.                 xor     al,al                   ;make a zero
  18. @@Compare:      mov     ch,al                   ;we want ch=0 for next count, if any
  19.                 mov     si,dx                   ;get back pointer to string sought
  20.                 mov     cl,ah                   ;get length
  21.                 mov     si,dx                   ;get pointer to string sought
  22.                 repe    cmpsb                   ;compare bytes
  23.                 jne     @@Skip                  ;if compare fails, try next string
  24.                 cmp     [Byte es:di],'='        ;compare succeeded. Is next char '='?
  25.                 jne     @@NoEqual               ;if not, still no match
  26. @@Found:        mov     ax,es                   ;make DS:SI point to string we found
  27.                 mov     ds,ax
  28.                 mov     si,di
  29.                 inc     si                      ;get past the equal (=) sign
  30.                 pop     cx bx es
  31.                 mov     di,bx                   ;put it in ES:DI
  32. CopyLoop:       lodsb                           ;get a byte
  33.                 or      al,al                   ;zero test
  34.                 je      @@Done                    ;if zero, we're done
  35.                 stosb                           ;put it in the result
  36.                 loop    CopyLoop                ;move up to 255 bytes
  37. @@Done:         not     cl                      ;we've been decrementing CL from
  38.                                                 ; 255 during save
  39.                 mov     al,0
  40.                 stosb
  41.                 ret
  42. @@Skip:         dec     di                      ;check for null from this char on
  43. @@NoEqual:      mov     cx,7FFFh                ;search a long way if necessary
  44.                 sub     cx,di                   ;environment never >32K
  45.                 jbe     @@RetNul                ;if we're past end, leave
  46.                 repne   scasb                   ;look for the next null
  47.                 jcxz    @@RetNul                ;exit if not found
  48.                 cmp     [Byte es:di],al         ;second null in a row?
  49.                 jne     @@Compare               ;if not, try again
  50. @@RetNul:       pop     cx di es
  51.                 stosb                           ;store a zero there
  52.                 ret
  53. endp            sl_EnvString
  54.  
  55. GUSPort     dw    2
  56. GUSIRQ        dw    5
  57. GUSMIDI     dw    3
  58. DMAIn        dw    1
  59. DMAOut        dw    1
  60. TerminateFlag    dw    1
  61. GUSIRQList      db      0,2,3,5,7,11,12,15
  62.  
  63. proc        SetEnv
  64.         mov    cx,80
  65.                 mov     ax,MyData
  66.                 mov     ds,ax
  67.                 mov     es,ax
  68.                 mov     ax,[cs:PspAddress]
  69.                 mov     si,offset GEnv
  70.                 mov     di,offset GDirectory
  71.                 call    sl_EnvString
  72.                 mov     ax,MyData
  73.                 mov     ds,ax
  74.                 mov     es,ax
  75.                 mov     di,offset GDirectory
  76.                 cmp     [Byte di],0
  77.                 je      @@NoEnvironment
  78.                 mov     cx,80
  79. @@LookLoop:     cmp     [Byte di],0
  80.                 je      @@FoundIt
  81.                 inc     di
  82.                 loop    @@LookLoop
  83. @@FoundIt:      cmp     [Byte di-01h],'\'
  84.         je    @@OKEn
  85.                 mov     [Byte di],'\'
  86.                 mov     [Byte di+01h],0
  87.                 inc     di
  88. @@OKEn:     mov    [PutFilename],di
  89.                 jmp     @@OKEnv
  90. @@NoEnvironment:
  91.                 mov     dx,offset NoEnvFound
  92.                 call    Error
  93. @@OKEnv:    ret
  94. endp            SetEnv
  95.